package com.itheima.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {


    //       <bean   class="org.mybatis.spring.SqlSessionFactoryBean">
//        <!--配置连接池对象-->
//        <property name="dataSource" ref="dataSource"/>
//        <!--配置别名-->
//        <property name="typeAliasesPackage" value="com.itheima.bean"/>
    @Bean
    public SqlSessionFactoryBean SqlSessionFactoryBean(DataSource dataSource){
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setTypeAliasesPackage("com.itheima.bean");

        return bean;
    }


//       <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
//        <property name="basePackage" value="com.itheima.mapper"/>
//    </bean>

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer(){
        MapperScannerConfigurer bean = new MapperScannerConfigurer();
        bean.setBasePackage("com.itheima.mapper");
        return bean;
    }
}
